#!/usr/bin/python
# EXTRACT COMMON BASE.HTML FROM MULTIPLE *.HTML FILES

import sys, glob

HEAD = []
TAIL = []

files = []
contents = []

if __name__ == "__main__":
    l = None
    for fn in sys.argv[1:]:
        f = open(fn, "r")
        files.append(f)

    while f:
        ls = set(f.readline().strip() for f in files)
        if len(ls) == 1:
            HEAD.append(ls.pop())
        else:
            #for el in ls:
            #    print "\t"+el
            HEAD.append("\n{% block content %}{% endblock %}\n\n")
            break

    contents = [list(reversed(f.readlines())) for f in files]
    i = 0
    while i > -1:
        ls = set(line[i].strip() for line in contents)
        if len(ls) == 1:
            TAIL.append(ls.pop())
            i += 1
        else:
            i = -1

    (f.close() for f in files)

for l in HEAD + list(reversed(TAIL)):
    print l
